//
//  LiteratureGroupDetailViewController.m
//  homeland
//
//  Created by caesar on 14-8-8.
//  Copyright (c) 2014年 xzysun. All rights reserved.
//

#import "LiteratureGroupDetailViewController.h"
#import "CommonUtil.h"

@interface LiteratureGroupDetailViewController ()

@end

@implementation LiteratureGroupDetailViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.title = @"详情";
    [self configView];
}

-(void)configView{
    LiteratureGroupEntity *lgEntity = [_config objectForKey:@"dataItem"];
    
    _titleTextView.text = [CommonUtil dealNullObject:lgEntity.title];
    
    NSString *contentStr = [CommonUtil dealNullObject:lgEntity.content] ;
    if (! [[CommonUtil dealNullObject:lgEntity.limitCrowd] isEqualToString:@"" ]) {
        contentStr = [contentStr stringByAppendingFormat:@"%@%@",@"\n对象/人数：",[CommonUtil dealNullObject:lgEntity.limitCrowd]] ;
    }
    if (! [[CommonUtil dealNullObject:lgEntity.timeQuantum]isEqualToString:@"" ]) {
        contentStr = [contentStr stringByAppendingFormat:@"%@%@",@"\n时间/节数：",[CommonUtil dealNullObject:lgEntity.timeQuantum]] ;
    }
    if (! [[CommonUtil dealNullObject:lgEntity.address]isEqualToString:@"" ]) {
        contentStr = [contentStr stringByAppendingFormat:@"%@%@",@"\n地址：",[CommonUtil dealNullObject:lgEntity.address]] ;
    }
    _contentTvetView.text =contentStr;
    
    //计算高度
    CGFloat titleHeight = [self caculateHeightForString:_titleTextView.text AndFontSize:17.0f AndWitdh:311.0f];
    
    CGFloat contentHeight = [self caculateHeightForString:_contentTvetView.text AndFontSize:14.0f AndWitdh:300.0f];
    
    _titleTextView.frame = CGRectMake(10.0, 15, 301, titleHeight);
    _spitLable.frame = CGRectMake(10, CGRectGetHeight(_titleTextView.frame)+10 , 300, 1);
    _contentTvetView.frame = CGRectMake(10.0, CGRectGetHeight(_titleTextView.frame)+21, 300, contentHeight);
    
    [self.scrollView addSubview:self.myView];
    
    CGFloat totalHeight = MAX(CGRectGetMaxY(_contentTvetView.frame)+20, CGRectGetHeight(self.scrollView.frame));
    self.myView.frame = CGRectMake(0.0, 0.0, 320.0, totalHeight+50);
    self.scrollView.contentSize = self.myView.frame.size;
    [self.scrollView addSubview:self.myView];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
